package com.blog.controller.admin;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.support.RequestContextUtils;

import com.alibaba.fastjson.JSONObject;
import com.blog.pojo.Blog;
import com.blog.pojo.BlogType;
import com.blog.pojo.Blogger;
import com.blog.service.BlogService;
import com.blog.service.BlogTypeService;
import com.blog.service.BloggerService;
import com.blog.service.CommentService;
import com.blog.service.UserService;
import com.blog.util.UtilResponse;

/**
 * 管理员刷新后台缓存
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/admin/system")
public class SystemAdminController {

	@Resource
	private BlogService blogService;
	@Resource
	private BlogTypeService blogTypeService;
	@Resource
	private BloggerService bloggerService;
	
	@RequestMapping("/refreshSystem")
	public String refreshSystem(HttpServletResponse response,HttpServletRequest request) throws Exception{
		//容器  --  全局的储存信息的空间
		ServletContext application = RequestContextUtils.getWebApplicationContext(request).getServletContext();
		//查询博主信息
		Blogger blogger = bloggerService.find();
		blogger.setPassword(null);
		application.setAttribute("blogger", blogger);
		
		//查询博客类别以及博客的数量 list
 		List<BlogType> blogTypeCountList = blogTypeService.countList();
		application.setAttribute("blogTypeCountList", blogTypeCountList);
		
		//查询博客每月数量  list
		List<Blog> blogMonthCountList = blogService.countList();
		application.setAttribute("blogMonthCountList", blogMonthCountList);
		
		//返回成功操作
		JSONObject result = new JSONObject();
		result.put("success", true);
		UtilResponse.write(response, result);
		return null;
	}
	
}
